﻿#pragma once
#include "Common.h"
#include "ObjectPool.h"

class PageCache
{
public:
	static inline PageCache* getInstance()
	{
		return &_sInstan;
	}
	// 申请一个k页的span
	Span* NewSpan(size_t k);
	// 获取对象到span的映射
	Span* MapObjectToSpan(void* obj);
	// 释放span回pagecache
	void ReleaseListToSpan(Span* span);

	std::mutex _pageMtx;
private:
	PageCache()
	{}
	PageCache(const PageCache&) = delete;
private:
	SpanList _spanLists[N_PAGES];
	std::unordered_map<PAGE_ID, Span*> _idSpanMap;
	
	MemoryPool<Span> _spanPool;

	static PageCache _sInstan;
};
